package com.ken.controller.user;

import cn.hutool.core.bean.BeanUtil;
import com.ken.context.BaseContext;
import com.ken.dto.ShoppingCartDTO;
import com.ken.entity.Dish;
import com.ken.entity.Setmeal;
import com.ken.entity.ShoppingCart;
import com.ken.mapper.SetmealMapper;
import com.ken.result.Result;
import com.ken.service.DishService;
import com.ken.service.MealService;
import com.ken.service.UserShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags ="C端-用户购物车接口")
public class UserShoppingCartController {
    @Autowired
    private UserShoppingCartService userShoppingCartService;

    /**
     * 删除购物车中一个商品
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中一个商品:{}", shoppingCartDTO);
        userShoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> findShoppingCart(){
        List<ShoppingCart> list = userShoppingCartService.listByUserId();
        return Result.success(list);
    }

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) { //请求参数:套餐id，菜品id,口味
        log.info("添加购物车,商品信息为:{}", shoppingCartDTO);
        userShoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result<String> deleteAll(){
        userShoppingCartService.deleteAll();
        return Result.success();
    }
}
